<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User extends CI_Controller {

	function __construct()
    {
        // Call the Model constructor
        parent::__construct();
        $this->load->model('user_model');
        $this->load->model('booking_model');
    } 
	public function login()
	{
	    $this->form_validation->set_rules('email','password','required');
        $this->form_validation->set_error_delimiters('<span class="form-msg-error">', '</span>');
        $layout = array();
        if($this->form_validation->run())
    	{
    	    $email = $this->input->post('email', TRUE);
            $password = $this->input->post('password', TRUE);
            $user_id = $this->user_model->login($email, $password);
            if($user_id){
                redirect('/');
            }else{
                $layout["error"]= "email / password incorrect.";
            }
	    }
	    
	    $layout = $this->load->view('user/login',$layout,TRUE);
		$this->load->view('layout/template' , array("content" => $layout) );
	}
	
	public function logout()
    {
        $this->session->set_userdata('id', null);  
        $this->session->set_userdata('email', null);  
        $this->session->set_userdata('firstname', null); 
        $this->session->set_userdata('lastname', null); 
        redirect('/');
    }
    
    public function history()
    {
        if($this->session->userdata('id') == ''){
	        redirect('booking');
	    }
        $layout = array();
        $layout['bookings'] = $this->booking_model->get_by_user_id($this->session->userdata('id'));
        $layout = $this->load->view('user/history',$layout,TRUE);
		$this->load->view('layout/template' , array("content" => $layout) );
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */